#include "headfile.h"
#include "img_processing.h"

//#define SHOW_FUN_RUNTIME     //用以计算函数运行时间, 即算法的时间复杂度
uint8 val_row = 40;

#pragma section all "cpu1_dsram"
//将本语句与#pragma section all restore语句之间的全局变量都放在CPU1的RAM中


#ifdef SHOW_FUN_RUNTIME
uint32 runtime = 0, starttime;
#endif

void core1_main(void)
{
	disableInterrupts();
    IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
    //用户在此处调用各种初始化函数等


	//等待所有核心初始化完毕
	IfxCpu_emitEvent(&g_cpuSyncEvent);
	IfxCpu_waitEvent(&g_cpuSyncEvent, 0xFFFF);
    enableInterrupts();

    while(TRUE)
    {
		//用户在此处编写任务代码
        if(mt9v03x_finish_flag)
        {
#ifdef SHOW_FUN_RUNTIME
            starttime = systick_getval_us(STM1);
#endif
            Get_Use_Image();
            Get_Bin_Image(2);
            mt9v03x_finish_flag=0;
            Bin_Image_Filter();
            seek_side();

            zebra = 0;
            for(uint8 row = 32; row < 40; row += 2){
                for(uint8 col = BIAS - 17; col < BIAS + 17; ++col)
                    zebra +=  Bin_Image[row][col];
            }

//            val_row = jump_limit();
            /* 发车时检测车库边缘 */
            if(run_start){
                row_cnt = 0;

                if(2 == global_param.run_dir){
                    for(uint8 i=0; i < 40; i += 2){
                        if(brim_L[i] > 0){
                            row_cnt ++;
                        }
                    }
                }else if(1 == global_param.run_dir){
                    for(uint8 i=0; i < 40; i += 2){
                        if(brim_R[i] > 0){
                            row_cnt ++;
                        }
                    }
                }
            }

#ifdef SHOW_FUN_RUNTIME
            runtime = systick_getval_us(STM1) - starttime;
#endif
        }
    }
    while(TRUE);
}


#pragma section all restore
